package StringHelper

import "errors"

/*
*
字符串截取
*/
func SubStr(str string, start int, end int) (string, error) {
	if len(str) == 0 {
		return str, nil
	}
	//if start > end {
	//	return "", errors.New("end max be than start")
	//}
	if start > end && end > 0 {
		return "", errors.New("end max be than start")
	}
	//当start >-1 且end小于,则以start 开始
	if start > -1 && end < 1 {
		return str[start:], nil
	} else if start > -1 && end > 0 && end > start {
		//当start 大一-1 且 end大于0 且end>start
		return str[start:end], nil
	} else if start < 0 && end > 0 {
		strLen := len(str)
		if strLen <= end {
			return str, nil
		}
		st := strLen - end
		return str[st:], nil

	} else {
		return "", errors.New("un normal intercept parameter")
	}
}
